package twodimension;

public class MatrixDemo {

    public static void main(String[] args) {
        int[][] matrixA = {{1, 2, 3}, {4, 5, 6}};
        int[][] matrixB = {{1, 2}, {3, 4}, {5, 6}};

        int[][] result = new int[2][2];

        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result[i].length; j++) {
                int temp = 0;
                for (int k = 0; k < matrixA[i].length; k++) {
                    temp += matrixA[i][k] * matrixB[k][j]; //A矩阵的行数对应result的i,B矩阵的列数对应result  j;
                }
                result[i][j] = temp;
            }
        }

        System.out.println("-------------输出结果-------------");
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result[i].length; j++) {
                System.out.print(result[i][j] + " ");
            }
            System.out.println();
        }
    }
}
